package com.tg.app.activity.device.settings;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;

import com.tg.app.R;
import com.tg.app.activity.base.DeviceSettingsListBaseActivity;
import com.tg.app.activity.device.DeviceSettingsActivity;
import com.tg.data.bean.DeviceSettingsInfo;
import com.appbase.custom.base.SettingData;
import com.appbase.custom.constant.CommonConstants;

import java.util.ArrayList;

public class PlaySleep4GActivity extends DeviceSettingsListBaseActivity {

    private ArrayList<SettingData> list = new ArrayList<>();
    private long [] sleeps  = {CommonConstants.SLEEP_LOCK_TIME_DEFAULT,10*60*1000,15*60*1000};
    private DeviceSettingsInfo  info;
    @Override
    protected void onSetupFailed() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        info = getIntent().getParcelableExtra(DeviceSettingsActivity.EXT_DEVICE_INFO);
        if (info.sleepTime==0){
            info.sleepTime = sleeps[0];
        }
        initView();
        initData();

    }

    @Override
    public boolean shouldSetStatusBarColor() {
        return true;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle(R.string.settings_device_sleep);
        getListView().setOnItemClickListener((parent, view, position, id) -> {
            if (getListView().getHeaderViewsCount() > 0) {
                position -= getListView().getHeaderViewsCount();
            }
            setFlag(position);
            if (position<sleeps.length){
                info.sleepTime = sleeps[position];
                sendUpdateSettingBroadcast(info);
            }


        });
        TextView textView = findViewById(R.id.setting_base_list_title);
        textView.setText(R.string.settings_device_sleep_tips);
        textView.setVisibility(View.VISIBLE);
    }

    private void initData() {
        String[] weeks = getResources().getStringArray(R.array.device_sleeps);
        for (int i = 0; i < weeks.length; i++) {
            SettingData data = new SettingData(weeks[i], 0);
             if (i<sleeps.length&&info.sleepTime==sleeps[i]){
                 data.setFlag(1);
             }
            list.add(data);
        }
        setDataList(list);
        getAdapter().notifyDataSetChanged();
    }

}
